
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.aspas.persistencia;

import br.com.aspas.modelo.Etiqueta;
import br.com.aspas.modelo.Evento;
import br.com.aspas.modelo.PessoaFisica;
import br.com.aspas.util.AbstractDAO;
import java.util.Date;
/**
 *
 * @author Reinaldo Viana
 */
public class EtiquetaDao extends AbstractDAO {

    public EtiquetaDao() {
    }

    public void inserir(Etiqueta etiqueta) {
        etiqueta.setDataInclusao(new Date());
        insert(etiqueta);
    }

    public Etiqueta findByPk(Integer pKey) {
        return (Etiqueta) findByPk(Etiqueta.class, pKey);
    }

    public Boolean remove(Integer id) {
        delete(id, Etiqueta.class);
        return new Boolean(true);
    }

    public Boolean removePessoa(Integer id) {

        deleteDinamic("Etiqueta e", "where e.pessoaFisica.codigo=" + id);
        return new Boolean(true);
    }

    public void altera(Etiqueta etiqueta) {
        etiqueta.setDataModificacao(new Date());
        update(etiqueta);
    }

    public Long totalEtiquetas(Integer codEvento) {
        em = emf.createEntityManager();
        Long count = (Long) em.createQuery("SELECT count(e) FROM Etiqueta e where e.pessoaFisica.evento.codigo=" + codEvento + " ").getSingleResult();
        em.close();
        return count;
    }

    public Long totalEtiquetas(Evento evento) {
        em = emf.createEntityManager();
        Long count = (Long) em.createQuery("SELECT count(e) FROM Etiqueta e " +
                "where e.pessoaFisica.evento=? ").setParameter(1, evento).getSingleResult();
        em.close();
        return count;
    }

    public Long totalEtiquetas() {
        em = emf.createEntityManager();
        Long count = (Long) em.createQuery("SELECT count(e) FROM Etiqueta e ").getSingleResult();
        em.close();
        return count;
    }

    public void removerEtiqueta(PessoaFisica pessoaFisica, Evento evento){
        deleteDinamic("Etiqueta e", "where e.pessoaFisica.codigo=" + pessoaFisica.getCodigo() +
                " and e.evento.codigo = "+evento.getCodigo());
    }


}

